<?php

function verify_names($names, $db, $system_id) {
	$nlook = array ( );
	$names = trim($names);
	$exam = explode ( "\n", $names );
	while ( list ( $n, $name ) = each ( $exam ) ) {
		$name = ucfirst ( trim ( strtolower ( strip_tags ( $name ) ) ) );
		$sql = "select * from wm_characters where character_system_id = $system_id and character_name='$name' and character_approved=1";
		$result = $db->query ( $sql );
		if ($db->num_rows ( $result ) != 1) {
			die("Unrecognized character '$name'.  Please make sure he or she is registered and approved.");
			//header ( "Location: $war_http/error.php?error='$err'" );
			//exit ();
		}
		$chara = $db->fetch_assoc ( $result );
		$nlook [$name] = $chara ["character_id"];
	}
	return $nlook;
}

function adminfeature() {
	global $pun_http, $war_http;
	echo '<img src="' . $war_http . '/images/admin.gif" alt="Admin Feature">';
}

function cclass($class) {
	global $war_http;
	echo '<img src="' . $war_http . '/images/' . $class . '.gif" alt="' . $class . '.gif" title="' . $class . '">';
}

function time_select($postfix = "", $preset = 0) {
	if($preset > 0) $now = $preset;
	else $now = time ();

	echo '<select name="hour' . $postfix . '">';

	$i = 00;
	while ( $i <= 23 ) {
		$chk = "";
		if ((date ( "H", $now )) == $i) {
			$chk = " selected";
		}
		echo "<option value=\"$i\" $chk>$i";
		$i ++;
	}
	echo '</select> : ';
	echo '<select name="minute' . $postfix . '">';

	$i = 0;
	while ( $i <= 59 ) {
		$chk = "";

		if ((date ( "i", $now )) == $i) $chk = " selected";
		echo "<option value=\"$i\" $chk>";

		if ($i < 10) echo "0";
		echo $i;
		$i ++;
	}
	echo "</select>";

}


function sqltounix($sqltime, $test = 0) {
	global $debug;
	if($sqltime > 0 && $test == 1) {
		$raidtime = @mktime($sqltime);
		return $raidtime;
	}
	elseif($sqltime > 0) {
		$hour = substr($sqltime, -8, 2)."<br>";
		$minute = substr($sqltime, -5, 2)."<br>";
		$second = substr($sqltime, -2, 2)."<br>";
		$month = substr($sqltime, 5, 2)."<br>";
		$day = substr($sqltime, 8, 2)."<br>";
		$year = substr($sqltime, 0, 4)."<br><p><br>";
		$raidtime = @mktime($hour, $minute, $second, $month, $day, $year);
		return $raidtime;
	}
	elseif($debug > 0) echo "Bad argument passed to 'sqltounix', please contact an administrator.<br>\n";
	else die('Error in sqltime: '.$sqltime.'. Contact administrator.<br>');
}



function date_select($predate = 0) {
	if ($predate > 0) $now = $predate;
	else $now = time ();
	echo '<select name="month">';

	$mnt [0] = "January";
	$mnt [1] = "February";
	$mnt [2] = "March";
	$mnt [3] = "April";
	$mnt [4] = "May";
	$mnt [5] = "June";
	$mnt [6] = "July";
	$mnt [7] = "August";
	$mnt [8] = "September";
	$mnt [9] = "October";
	$mnt [10] = "November";
	$mnt [11] = "December";

	$i = 0;
	while ( $i < 12 ) {
		$chk = "";
		if ((date ( "n", $now )) - 1 == $i) {
			$chk = " selected";
		}
		echo '<option value="'.$i.'" '.$chk.'>'.$mnt [$i];
		$i ++;
	}

	echo "</select> <select name=\"day\">\n";

	$i = 1;
	while ( $i <= 32 ) {
		$chk = "";
		if ((date ( "j", $now )) == $i) {
			$chk = " selected";
		}
		echo '<option value="'.$i.'" '.$chk.'>'.$i;
		$i ++;
	}

	echo "</select> <select name=\"year\">\n";

	$i = (date ( "Y", $now )) - 2;
	while ( $i <= ((date ( "Y", $now ) + 2)) ) {
		$chk = "";
		if ((date ( "Y", $now )) == $i) {
			$chk = " selected";
		}
		echo '<option value="'.$i.'" '.$chk.'>'.$i;
		$i ++;
	}
	echo "</select>\n";
}

function sql_debug($ser) {
	global $debug_active;

	if($debug_active == "yes"){
		echo '<div class="debug">';
		echo "Mysql error no:<b> ".$ser['error_no']."</b><br>\n";
		echo "<i> ".$ser['error_msg']."</i><br>\n";
		echo "</div><br>\n";
	}
}

?>